/**      
*  @Title:  XinHeHuiApiServiceImpl.java  
*  @Package  com.zjdiepu.www.biz.zpp  
*    
*  @author  zhangpp
*  @date  2017年9月25日  下午2:10:10  
*  @version  V1.0      
*/
package com.zjdiepu.www.biz.zpp;
import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;

import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.diepu.www.client.xhh.partner.request.DiepuMuJiOrJihuaApi;
import com.diepu.www.client.xhh.partner.request.QueryStatusRequest;
import com.diepu.www.client.xhh.partner.response.QueryRaiseResponse;
import com.google.gson.Gson;
import com.zjdiepu.www.base.core.BaseException;
import com.zjdiepu.www.base.enums.status.ThirdBusiStatus;
import com.zjdiepu.www.base.enums.status.ThirdHandleStatus;
import com.zjdiepu.www.base.enums.status.TrailerStatus;
import com.zjdiepu.www.base.enums.type.ResultFlagType;
import com.zjdiepu.www.base.enums.type.ThirdModeIDType;
import com.zjdiepu.www.common.util.CollectionInitUtil;
import com.zjdiepu.www.common.util.ZhppDateUtil;
import com.zjdiepu.www.consts.XhhService;
import com.zjdiepu.www.dao.partner.ThBusinessRecordMapper;
import com.zjdiepu.www.dao.partner.ThCollectMapper;
import com.zjdiepu.www.dao.partner.ThHandleErrMapper;
import com.zjdiepu.www.dao.partner.ThLogsMapper;
import com.zjdiepu.www.dao.partner.ThLogsSubMapper;
import com.zjdiepu.www.dao.partner.ThRepaymentMapper;
import com.zjdiepu.www.dao.partner.ThRepaymentScheduleMapper;
import com.zjdiepu.www.dao.partner.ThYwBusinessMapper;
import com.zjdiepu.www.dao.yw.YwBusinessMapper;
import com.zjdiepu.www.dao.zpp.PublicDao;
import com.zjdiepu.www.ibiz.partner.IThHandleErrService;
import com.zjdiepu.www.ibiz.zpp.XinHeHuiApiService;
import com.zjdiepu.www.model.partner.dto.ThBusinessRecord;
import com.zjdiepu.www.model.partner.dto.ThCollect;
import com.zjdiepu.www.model.partner.dto.ThHandleErr;
import com.zjdiepu.www.model.partner.dto.ThLogs;
import com.zjdiepu.www.model.partner.dto.ThLogsSub;
import com.zjdiepu.www.model.partner.dto.ThRepaymentSchedule;
import com.zjdiepu.www.model.partner.dto.ThYwBusiness;
import com.zjdiepu.www.model.yw.dto.YwBusiness;
import com.zjdiepu.www.util.CommonUtil;
import com.zjdiepu.www.xhh.XinHeHuiClient;

/**            
 *  项目名称：diepu-parent-biz      
 *  类名称：XinHeHuiApiServiceImpl      
 *  类描述：      
 *  创建人：zhangpp
 *  创建时间：2017年9月25日  下午2:10:10      
 *  修改人：zhangpp
 *  修改时间：2017年9月25日  下午2:10:10      
 *  修改备注：      
 *  @version  V1.0          
 */
@Service
public class XinHeHuiApiServiceImpl implements XinHeHuiApiService
{
	private final Logger logger = LoggerFactory.getLogger(XinHeHuiApiServiceImpl.class);
	
	private int successCode = 0;
	
	@Autowired
	private YwBusinessMapper ywBusinessMapper;
	
	@Autowired
	private ThYwBusinessMapper thYwBusinessMapper;
	
	@Autowired
	private ThLogsMapper thLogsMapper;
	
	@Autowired
	private IThHandleErrService thHandleErrService;
	
	@Autowired
	private ThHandleErrMapper thHandleErrMapper;
	
	@Autowired
	private ThLogsSubMapper thLogsSubMapper;
	
	@Autowired
	private ThBusinessRecordMapper thBusinessRecordMapper;
	
	@Autowired
	private PublicDao publicDao;
	
	@Autowired
	private ThCollectMapper thCollectMapper;
	
	@Autowired
	private ThRepaymentMapper thRepaymentMapper;
	
	@Autowired
	private ThRepaymentScheduleMapper thRepaymentScheduleMapper;
	
	
	
	/*  
	*  @author  zhangpp
	*  <p>Title:  diepuMuJiOrJihuaApi</p>  
	*  <p>Description:  </p>  
	*  @param currentUser
	*  @param busiId  
	*  @see com.zjdiepu.www.ibiz.zpp.XinHeHuiApiService#diepuMuJiOrJihuaApi(com.zjdiepu.www.base.core.AbstractSysUser, java.lang.String)  
	*  @version  V1.0
	*/
	@Override
	public String diepuMuJiOrJihuaApi(String currentUserId, String currentUserName, String busiId,String busiType) 
	{
		
		
		//请求的字符串
		String requestJsonString = null;
		
		//相应结果集
		QueryRaiseResponse queryRaiseResponse = null;
		
		//请求的地址
		String preRequestUrl = null;
		
		//请求的参数
		Map<String, String> preRequestParam = null;
		
		//参数集
		QueryStatusRequest queryStatusRequest = null;
		
		//碟普查询的结果集
		ThYwBusiness thYwBusiness = null;
		
		//碟普业务数据结果集
		YwBusiness ywBusiness = null;
		
		//请求返回结果集
		DiepuMuJiOrJihuaApi raiseRequest = null;
		
		//请求用户编号
		String userId = currentUserId;
		
		//请求用户名称
		String loginName = currentUserName;
		
		try 
		{
			
			if(StringUtils.isBlank(busiId)) 
			{ 
				throw new BaseException(ResultFlagType.MISSING.getCode().toString(),"busiId is null");
			}
			
			ywBusiness = ywBusinessMapper.selectByPrimaryKey(busiId);
			if(null == ywBusiness)
			{
				throw new BaseException(ResultFlagType.MISSING.getCode().toString(),"ywBusinessMapper is null");
			}
			
			thYwBusiness = new ThYwBusiness();
			thYwBusiness.setBusiId(busiId);
			thYwBusiness.setBusiType(busiType);
			thYwBusiness.setDpStatus(1);
			thYwBusiness = thYwBusinessMapper.selectRefined(thYwBusiness);
			if(null == thYwBusiness)
			{
				throw new BaseException(ResultFlagType.MISSING.getCode().toString(),"thYwBusinessMapper is null");
			}
			
			//参数集
			queryStatusRequest = new QueryStatusRequest();
			System.err.println(thYwBusiness.getThirdId());
			queryStatusRequest.setXeApplyNo(thYwBusiness.getThirdId());
			
			//获取鑫合汇募集结果查询  地址  和  参数
			preRequestUrl = XinHeHuiClient.preRequestUrl(XhhService.QUERY_RAISE);
			preRequestParam = XinHeHuiClient.preRequestParam(queryStatusRequest);
			
			
		} 
		catch (Exception e) 
		{
			String dataId = "";
			String thirdId = "";
			if(null != thYwBusiness)
			{
				dataId = thYwBusiness.getId();
			}
			if(null != thYwBusiness)
			{
				thirdId = thYwBusiness.getThirdId();
			}
			Map<String, String> aValue = CollectionInitUtil.emptyMap();
			aValue.put("errLogFlag", "error");
			aValue.put("userId",userId);
			aValue.put("loginName",loginName);
			aValue.put("busiType", busiType);
			aValue.put("dataId", dataId);
			aValue.put("busiType", busiType);
			aValue.put("busiId", busiId);
			aValue.put("thirdId", thirdId);
			aValue.put("thirdModeId", ThirdModeIDType.MJHHKJHSCCX.getCode());
			aValue.put("thirdModeName", ThirdModeIDType.MJHHKJHSCCX.getValue());
			aValue.put("describeEvent", ThirdModeIDType.MJHHKJHSCCX.getValue());
			aValue.put("statusEvent", "1");
			aValue.put("requestMessageEvent", "鑫合汇募集结果查询  preRequestUrl preRequestParam 出错");
			aValue.put("responseMessageEvent", "");
			aValue.put("requestMessageEventEncode", ResultFlagType.FAIL.getCode().toString());
			aValue.put("thirdHandleStatus", String.valueOf(ThirdHandleStatus.FA_SONG_SHI_BAI.getCode()));
			aValue.put("thirdHandleStatusName", ThirdHandleStatus.FA_SONG_SHI_BAI.getValue());
			aValue.put("errInfo", "鑫合汇募集结果查询   preRequestUrl  和  preRequestParam  生成  出错");
			diepuLogError(currentUserId, currentUserName, aValue);
			logger.error(e.getMessage());
			return "requestUrlError";
		}
		
		
		try 
		{
			//执行请求接口
			//System.out.println(JSON.toJSONString(preRequestParam));
			requestJsonString = XinHeHuiClient.request(preRequestUrl, preRequestParam);
			JSONObject json = CommonUtil.getJSONObject(requestJsonString);
			
			//信合会返回标识
			int errCode = json.getInt("errcode");
			if(errCode == successCode)
			{
				raiseRequest = new Gson().fromJson(requestJsonString, DiepuMuJiOrJihuaApi.class);
				if(null == raiseRequest)
				{
					throw new BaseException(ResultFlagType.PARAM_EMPTY.getCode().toString(),"raiseRequest is null");
				}
				
				//成功的标识
				if(raiseRequest.getErrcode() == successCode)
				{
					//募集状态值
					Integer loan_status = raiseRequest.getData().getLoan_status();
					if(null == loan_status)
					{
						throw new BaseException(ResultFlagType.PARAM_EMPTY.getCode().toString(),"loan_status is null");
					}
					
					//如果是生成计划完成
					if(loan_status >= Integer.valueOf(TrailerStatus.LOAN_STATUS4.getCode()) && loan_status < 6)
					{
						//还款计划
						ThRepaymentSchedule thRepaymentSchedule = new ThRepaymentSchedule();
						thRepaymentSchedule.setBusiType(busiType);
						thRepaymentSchedule.setBusiId(busiId);
						thRepaymentSchedule.setDpStatus(1);
						thRepaymentSchedule = thRepaymentScheduleMapper.selectRefined(thRepaymentSchedule);
						if(null != thRepaymentSchedule)
						{
							int count = thRepaymentScheduleMapper.deleteByPrimaryKey(thRepaymentSchedule.getId());
							if(count < 1)
							{
								throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"thRepaymentScheduleMapper delete error");
							}
						}
						
						//还款计划
						thRepaymentSchedule = new ThRepaymentSchedule();
						thRepaymentSchedule.initInsertData(userId, loginName);
						thRepaymentSchedule.setBusiType(busiType);
						thRepaymentSchedule.setBusiId(busiId);
						thRepaymentSchedule.setThirdId(thYwBusiness.getId());
						thRepaymentSchedule.setThirdId(thYwBusiness.getThirdId());
						thRepaymentSchedule.setProjectName(raiseRequest.getData().getProject_name());
						thRepaymentSchedule.setProjectNo(raiseRequest.getData().getProject_name());
						thRepaymentSchedule.setBorrowerStartDate(ZhppDateUtil.convertDate(raiseRequest.getData().getBorrower_start_date(), ZhppDateUtil.SHORT_DATE_FORMAT));
						thRepaymentSchedule.setBorrowerPeriods(raiseRequest.getData().getBorrower_periods());
						thRepaymentSchedule.setBorrowerPeriodsUnit(raiseRequest.getData().getBorrower_periods_unit());
						thRepaymentSchedule.setBorrowerRepayDate(ZhppDateUtil.convertDate(raiseRequest.getData().getBorrower_repay_date(), ZhppDateUtil.SHORT_DATE_FORMAT));
						thRepaymentSchedule.setBorrowerYearRate(raiseRequest.getData().getBorrower_year_rate());
						thRepaymentSchedule.setActualRaiseFee(raiseRequest.getData().getActual_raise_fee());
						thRepaymentSchedule.setPlatformServiceFee(BigDecimal.valueOf(raiseRequest.getData().getPlatform_service_fee()));
						thRepaymentSchedule.setRepayAmount(BigDecimal.valueOf(raiseRequest.getData().getRepay_amount()));
						thRepaymentSchedule.setRepayPrincipal(BigDecimal.valueOf(raiseRequest.getData().getRepay_principal()));
						thRepaymentSchedule.setRepayInterest(BigDecimal.valueOf(raiseRequest.getData().getRepay_interest()));
						thRepaymentSchedule.setScheduleStatus(10);
						thRepaymentSchedule.setScheduleStatusName("生成还款计划完成");
						thRepaymentSchedule.setRemarks("xhh还款计划");
						int count = thRepaymentScheduleMapper.insert(thRepaymentSchedule);
						if(count < 1)
						{
							throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"thRepaymentScheduleMapper insert error");
						}
						
						
						//将yw_业务信息表的第三方渠道业务状态值更改为‘划款计划’
						ThYwBusiness ywThYwBusiness = new ThYwBusiness();
						ywThYwBusiness.initUpdateData(userId, loginName);
						ywThYwBusiness.setId(thYwBusiness.getId());
						if(thYwBusiness.getThirdBusiStatus() < 600)
						{
							ywThYwBusiness.setThirdBusiStatus(ThirdBusiStatus.HUAN_KUAN_JI_HUA_CHENG_GONG.getCode());
						}
						count = thYwBusinessMapper.updateByPrimaryKeySelective(ywThYwBusiness);
						if(count < 1)
						{
							throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"thYwBusinessMapper insert error");
						}
						
						//将yw_业务信息表的第三方渠道业务状态值更改为‘划款计划’
						YwBusiness business = new YwBusiness();
						business.initUpdateData(userId, loginName);
						business.setId(busiId);
						if(ywBusiness.getThirdBusiStatus() < 600)
						{
							business.setThirdBusiStatus(ThirdBusiStatus.HUAN_KUAN_JI_HUA_CHENG_GONG.getCode());
						}
						business.setActualRaiseFee(raiseRequest.getData().getActual_raise_fee());
						count = ywBusinessMapper.updateByPrimaryKeySelective(business);
						if(count < 1)
						{
							throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"ywBusinessMapper insert error");
						}
						
						ThBusinessRecord thBusinessRecord = new ThBusinessRecord();
						thBusinessRecord.setBusiId(busiId);
						thBusinessRecord.setThirdModeId(ThirdModeIDType.HKJHWCTZ.getCode());
						thBusinessRecord.setBusiType(busiType);
						thBusinessRecord.setDpStatus(1);
						thBusinessRecord = thBusinessRecordMapper.selectRefined(thBusinessRecord);
						if(null != thBusinessRecord)
						{
							count = thBusinessRecordMapper.deleteByPrimaryKey(thBusinessRecord.getId());
							if(count < 1)
							{
								throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"thBusinessRecordMapper delete error");
							}
						}
						//第三方信息履历
						thBusinessRecord = new ThBusinessRecord();
						thBusinessRecord.initInsertData(userId, loginName);
						thBusinessRecord.setDataId(thYwBusiness.getId());
						thBusinessRecord.setBusiType(busiType);
						thBusinessRecord.setBusiId(busiId);
						thBusinessRecord.setThirdId(thYwBusiness.getThirdId());
						thBusinessRecord.setThirdModeId(ThirdModeIDType.HKJHWCTZ.getCode());
						thBusinessRecord.setThirdModeName(ThirdModeIDType.HKJHWCTZ.getValue());
						thBusinessRecord.setRecordEvent(TrailerStatus.LOAN_STATUS4.getValue());
						count = thBusinessRecordMapper.insert(thBusinessRecord);
						if(count < 1)
						{
							throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"thBusinessRecordMapper insert error");
						}
					}
					
					//募集处理
					else if(loan_status > 0 && loan_status <= 4)
					{
						ThBusinessRecord thBusinessRecord = new ThBusinessRecord();
						thBusinessRecord.setBusiId(busiId);
						thBusinessRecord.setThirdModeId(ThirdModeIDType.MJHHKJHSCCX.getCode());
						thBusinessRecord.setBusiType(busiType);
						thBusinessRecord.setDpStatus(1);
						thBusinessRecord = thBusinessRecordMapper.selectRefined(thBusinessRecord);
						
						//删除
						if(null != thBusinessRecord)
						{
							int count = thBusinessRecordMapper.deleteByPrimaryKey(thBusinessRecord.getId());
							if(count < 1)
							{
								throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"thBusinessRecordMapper delete error");
							}
						}
						
						//第三方信息履历
						thBusinessRecord = new ThBusinessRecord();
						thBusinessRecord.initInsertData(userId, loginName);
						thBusinessRecord.setDataId(thYwBusiness.getId());
						thBusinessRecord.setBusiType(busiType);
						thBusinessRecord.setBusiId(busiId);
						thBusinessRecord.setThirdId(thYwBusiness.getThirdId());
						thBusinessRecord.setThirdModeId(ThirdModeIDType.MJHHKJHSCCX.getCode());
						thBusinessRecord.setThirdModeName(ThirdModeIDType.MJHHKJHSCCX.getValue());
						thBusinessRecord.setRecordEvent(TrailerStatus.LOAN_STATUS1.getValue());
						int count = thBusinessRecordMapper.insert(thBusinessRecord);
						if(count < 1)
						{
							throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"thBusinessRecordMapper insert error");
						}
						
						//第三方募集信息
						ThCollect thCollect = new ThCollect();
						thCollect.setBusiId(busiId);
						thCollect.setBusiType(busiType);
						thCollect.setDpStatus(1);
						thCollect = thCollectMapper.selectRefined(thCollect);
						
						//删除
						if(null != thCollect)
						{
							count = thCollectMapper.deleteByPrimaryKey(thCollect.getId());
							if(count < 1)
							{
								throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"thCollectMapper delete error");
							}
						}
						
						thCollect = new ThCollect();
						thCollect.initInsertData(userId, loginName);
						thCollect.setBusiType(busiType);
						thCollect.setBusiId(busiId);
						thCollect.setThirdId(thYwBusiness.getThirdId());
						thCollect.setProjectName(raiseRequest.getData().getProject_name());
						thCollect.setProjectNo(raiseRequest.getData().getProject_name());
						thCollect.setBorrowerStartDate(ZhppDateUtil.convertDate(raiseRequest.getData().getBorrower_start_date(), ZhppDateUtil.SHORT_DATE_FORMAT));
						thCollect.setBorrowerPeriods(raiseRequest.getData().getBorrower_periods());
						thCollect.setBorrowerPeriodsUnit(raiseRequest.getData().getBorrower_periods_unit());
						thCollect.setCollectStatus(Integer.valueOf(TrailerStatus.LOAN_STATUS1.getCode()));
						thCollect.setCollectStatusName(TrailerStatus.LOAN_STATUS1.getValue());
						thCollect.setBorrowerRepayDate(ZhppDateUtil.convertDate(raiseRequest.getData().getBorrower_repay_date(), ZhppDateUtil.SHORT_DATE_FORMAT));
						thCollect.setBorrowerYearRate(raiseRequest.getData().getBorrower_year_rate());
						thCollect.setActualRaiseFee(raiseRequest.getData().getActual_raise_fee());
						count = thCollectMapper.insert(thCollect);
						if(count < 1)
						{
							throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"thCollectMapper insert error");
						}
						
						//将yw_业务信息表的第三方渠道业务状态值更改为‘募集完成’
						ThYwBusiness ywThYwBusiness = new ThYwBusiness();
						ywThYwBusiness.initUpdateData(userId, loginName);
						ywThYwBusiness.setId(thYwBusiness.getId());
						if(thYwBusiness.getThirdBusiStatus() < 550)
						{
							ywThYwBusiness.setThirdBusiStatus(ThirdBusiStatus.MU_JI_WAN_CHENG.getCode());
						}
						count = thYwBusinessMapper.updateByPrimaryKeySelective(ywThYwBusiness);
						if(count < 1)
						{
							throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"thYwBusinessMapper insert error");
						}
						
						//将yw_业务信息表的第三方渠道业务状态值更改为‘募集完成’
						YwBusiness business = new YwBusiness();
						business.initUpdateData(userId, loginName);
						business.setId(busiId);
						if(ywBusiness.getThirdBusiStatus() < 550)
						{
							business.setThirdBusiStatus(ThirdBusiStatus.MU_JI_WAN_CHENG.getCode());
						}
						business.setActualRaiseFee(raiseRequest.getData().getActual_raise_fee());
						count = ywBusinessMapper.updateByPrimaryKeySelective(business);
						if(count < 1)
						{
							throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"ywBusinessMapper insert error");
						}
					}
				}
			}
			
			//日志
			String dataId = "";
			String thirdId = "";
			int errcode = -1;
			if(null != thYwBusiness)
			{
				dataId = thYwBusiness.getId();
			}
			if(null != thYwBusiness)
			{
				thirdId = thYwBusiness.getThirdId();
			}
			if(null != raiseRequest)
			{
				errcode = raiseRequest.getErrcode();
			}
			
			Map<String, String> aValue = CollectionInitUtil.emptyMap();
			aValue.put("errLogFlag", "log");
			aValue.put("userId",userId);
			aValue.put("loginName",loginName);
			aValue.put("dataId", dataId);
			aValue.put("busiType", busiType);
			aValue.put("busiId", busiId);
			aValue.put("thirdId", thirdId);
			aValue.put("thirdModeId", ThirdModeIDType.MJHHKJHSCCX.getCode());
			aValue.put("thirdModeName", ThirdModeIDType.MJHHKJHSCCX.getValue());
			aValue.put("describeEvent", ThirdModeIDType.MJHHKJHSCCX.getValue());
			aValue.put("statusEvent", "1");
			aValue.put("requestMessageEvent", "鑫合汇募集结果解析成功");
			aValue.put("responseMessageEvent", requestJsonString);
			aValue.put("requestMessageEventEncode",String.valueOf(errcode));
			aValue.put("thirdHandleStatus", String.valueOf(ThirdHandleStatus.FA_SONG_SHI_BAI.getCode()));
			aValue.put("thirdHandleStatusName", ThirdHandleStatus.FA_SONG_SHI_BAI.getValue());
			aValue.put("errInfo", "鑫合汇募集结果查询  request 出错");
			diepuLogError(currentUserId, currentUserName, aValue);
			
			//解析状态不成功则停止
			if(errCode != successCode)
			{
				return "requestJsonCodeError"+errCode;
			}
		} 
		catch (Exception e) 
		{
			
			String dataId = "";
			String thirdId = "";
			if(null != thYwBusiness)
			{
				dataId = thYwBusiness.getId();
			}
			if(null != thYwBusiness)
			{
				thirdId = thYwBusiness.getThirdId();
			}
			Map<String, String> aValue = CollectionInitUtil.emptyMap();
			aValue.put("errLogFlag", "error");
			aValue.put("userId",userId);
			aValue.put("loginName",loginName);
			aValue.put("dataId", dataId);
			aValue.put("busiType", busiType);
			aValue.put("busiId", busiId);
			aValue.put("thirdId", thirdId);
			aValue.put("thirdModeId", ThirdModeIDType.MJHHKJHSCCX.getCode());
			aValue.put("thirdModeName", ThirdModeIDType.MJHHKJHSCCX.getValue());
			aValue.put("describeEvent", ThirdModeIDType.MJHHKJHSCCX.getValue());
			aValue.put("statusEvent", "1");
			aValue.put("requestMessageEvent", "鑫合汇募集结果查询  request  出错");
			aValue.put("responseMessageEvent", "碟普 request 出错");
			aValue.put("requestMessageEventEncode",ResultFlagType.FAIL.getCode().toString());
			aValue.put("thirdHandleStatus", String.valueOf(ThirdHandleStatus.FA_SONG_SHI_BAI.getCode()));
			aValue.put("thirdHandleStatusName", ThirdHandleStatus.FA_SONG_SHI_BAI.getValue());
			aValue.put("errInfo", "鑫合汇募集结果查询  request 出错");
			diepuLogError(currentUserId, currentUserName, aValue);
			logger.error(e.getMessage());
			return "requestError";
		}
		
		
		try 
		{
			//请求处理的结果
			queryRaiseResponse = XinHeHuiClient.parseResponse(requestJsonString, QueryRaiseResponse.class);
			if(null == queryRaiseResponse)
			{
				throw new BaseException(ResultFlagType.PARAM_EMPTY.getCode().toString(),"queryRaiseResponse is null");
			}
			
		}
		catch (Exception e) 
		{
			
			String dataId = "";
			String thirdId = "";
			if(null != thYwBusiness)
			{
				dataId = thYwBusiness.getId();
			}
			if(null != thYwBusiness)
			{
				thirdId = thYwBusiness.getThirdId();
			}
			Map<String, String> aValue = CollectionInitUtil.emptyMap();
			aValue.put("errLogFlag", "error");
			aValue.put("userId",userId);
			aValue.put("loginName",loginName);
			aValue.put("dataId", dataId);
			aValue.put("busiType", busiType);
			aValue.put("busiId", busiId);
			aValue.put("thirdId", thirdId);
			aValue.put("thirdModeId", ThirdModeIDType.MJHHKJHSCCX.getCode());
			aValue.put("thirdModeName", ThirdModeIDType.MJHHKJHSCCX.getValue());
			aValue.put("describeEvent", ThirdModeIDType.MJHHKJHSCCX.getValue());
			aValue.put("statusEvent", "1");
			aValue.put("requestMessageEvent", "鑫合汇募集结果查询  response  出错");
			aValue.put("responseMessageEvent", "碟普  response 出错");
			aValue.put("requestMessageEventEncode",ResultFlagType.FAIL.getCode().toString());
			aValue.put("thirdHandleStatus", String.valueOf(ThirdHandleStatus.FA_SONG_SHI_BAI.getCode()));
			aValue.put("thirdHandleStatusName", ThirdHandleStatus.FA_SONG_SHI_BAI.getValue());
			aValue.put("errInfo", "鑫合汇募集结果查询  response 出错");
			diepuLogError(currentUserId, currentUserName, aValue);
			logger.error(e.getMessage());
			return "responseError";
		}
		return "success";
	}

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

	@Override
	public void diepuLogError(String currentUserId, String currentUserName, Map<String, String> aValue) 
	{
		
		
		String userId = aValue.get("userId");
		String loginName = aValue.get("loginName");
		String dataId = aValue.get("dataId");
		String busiType = aValue.get("busiType");
		String busiId = aValue.get("busiId");
		String thirdId = aValue.get("thirdId");
		String thirdModeId = aValue.get("thirdModeId");
		String thirdModeName = aValue.get("thirdModeName");
		String describeEvent = aValue.get("describeEvent");
		String statusEvent = aValue.get("statusEvent");
		String requestMessageEvent = aValue.get("requestMessageEvent");
		String responseMessageEvent = aValue.get("responseMessageEvent");
		String requestMessageEventEncode = aValue.get("requestMessageEventEncode");
		String thirdHandleStatus = aValue.get("thirdHandleStatus");
		String thirdHandleStatusName = aValue.get("thirdHandleStatusName");
		String errInfo = aValue.get("errInfo");
		String errLogFlag = aValue.get("errLogFlag");
		
		if(errLogFlag.equals("log"))
		{
			ThLogs thLogs = new ThLogs();
			thLogs.initInsertData(userId, loginName);
			thLogs.setDataId(dataId);
			thLogs.setBusiType(busiType);
			thLogs.setBusiId(busiId);
			thLogs.setThirdId(thirdId);
			thLogs.setThirdModeId(thirdModeId);
			thLogs.setThirdModeName(thirdModeName);
			thLogs.setDescribeEvent(describeEvent);
			thLogs.setStatusEvent(Integer.valueOf(statusEvent));
			int count = thLogsMapper.insert(thLogs);
			if(count < 1)
			{
				throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"thLogsMapper insert error");
			}
			
			ThLogsSub thLogsSub = new ThLogsSub();
			thLogsSub.initInsertData(userId, loginName);
			thLogsSub.setThLogsId(thLogs.getId());
			thLogsSub.setDataId(dataId);
			thLogsSub.setBusiType(busiType);
			thLogsSub.setBusiId(busiId);
			thLogsSub.setThirdId(thirdId);
			thLogsSub.setThirdModeId(thirdModeId);
			thLogsSub.setThirdModeName(thirdModeName);
			thLogsSub.setRequestMessageEvent(requestMessageEvent);
			thLogsSub.setResponseMessageEvent(responseMessageEvent);
			thLogsSub.setRequestMessageEventEncode(requestMessageEventEncode);
			count = thLogsSubMapper.insert(thLogsSub);
			if(count < 1)
			{
				throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"thLogsMapper insert error");
			}
			return;
		}
		
		ThLogs thLogs = new ThLogs();
		thLogs.initInsertData(userId, loginName);
		thLogs.setDataId(dataId);
		thLogs.setBusiType(busiType);
		thLogs.setBusiId(busiId);
		thLogs.setThirdId(thirdId);
		thLogs.setThirdModeId(thirdModeId);
		thLogs.setThirdModeName(thirdModeName);
		thLogs.setDescribeEvent(describeEvent);
		thLogs.setStatusEvent(Integer.valueOf(statusEvent));
		int count = thLogsMapper.insert(thLogs);
		if(count < 1)
		{
			throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"thLogsMapper insert error");
		}
		
		ThLogsSub thLogsSub = new ThLogsSub();
		thLogsSub.initInsertData(userId, loginName);
		thLogsSub.setThLogsId(thLogs.getId());
		thLogsSub.setDataId(dataId);
		thLogsSub.setBusiType(busiType);
		thLogsSub.setBusiId(busiId);
		thLogsSub.setThirdId(thirdId);
		thLogsSub.setThirdModeId(thirdModeId);
		thLogsSub.setThirdModeName(thirdModeName);
		thLogsSub.setRequestMessageEvent(requestMessageEvent);
		thLogsSub.setResponseMessageEvent(responseMessageEvent);
		thLogsSub.setRequestMessageEventEncode(requestMessageEventEncode);
		count = thLogsSubMapper.insert(thLogsSub);
		if(count < 1)
		{
			throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"thLogsMapper insert error");
		}
		
		ThHandleErr thHandleErr = new ThHandleErr();
		thHandleErr.initInsertData(userId, loginName);
		thHandleErr.setDataId(dataId);
		thHandleErr.setBusiType(busiType);
		thHandleErr.setBusiId(busiId);
		thHandleErr.setThirdId(thirdId);
		thHandleErr.setThirdModeId(thirdModeId);
		thHandleErr.setThirdModeName(thirdModeName);
		thHandleErr.setThLogId(thLogs.getId());
		thHandleErr.setThLogSubId(thLogsSub.getId());
		thHandleErr.setThirdHandleStatus(Integer.valueOf(thirdHandleStatus));
		thHandleErr.setThirdHandleStatusName(thirdHandleStatusName);
		thHandleErr.setErrInfo(errInfo);
		thHandleErr.setTimeNext(new Date());
		count = thHandleErrMapper.insert(thHandleErr);
		if(count < 1)
		{
			throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"thLogsMapper insert error");
		}
	}
}
